package com.jt.controller;

import com.jt.pojo.ContentCat;
import com.jt.service.ContentCatService;
import com.jt.vo.EasyUITree;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author dc
 * @Classname ContentController
 * @Date 2020/3/23 17:18
 */
@RestController
@RequestMapping("/content/category")
public class ContentCatController {

    @Autowired
    private ContentCatService contentCatService;

    @RequestMapping("/list")
    public List<EasyUITree> getContentCatByParentId(@RequestParam(value = "id",defaultValue = "0") Long parentId){
        List<EasyUITree> catList = contentCatService.getContentCatByParentId(parentId);
        return catList;
    }

    @RequestMapping("/create")
    public SysResult createNode(Long parentId,String name){
        ContentCat newNode=contentCatService.createNode(parentId,name);
        return SysResult.success(newNode);
    }

    @RequestMapping("/delete")
    public SysResult deleteNode(Long id){
        contentCatService.deleteNode(id);
        return SysResult.success();
    }

    @RequestMapping("/update")
    public SysResult updateNode(Long id,String name){
        contentCatService.updateNodeById(id,name);
        return SysResult.success();
    }

}
